#ifndef SOFTPLC_H
#define SOFTPLC_H


#include <plc_abi.h>

#if defined(__cplusplus)
extern "C"
{
#endif
//typedef unsigned int uint32_t;
//typedef unsigned short u16;
//typedef unsigned char u8;
//typedef int s32;
//typedef u8 bool;



int regVari(const char *buf, int len);

extern char *PLC_ID;

// extern unsigned long long common_ticktime__;
// extern TIME __CURRENT_TIME;
int RetainCmp(unsigned int offset, unsigned int count, void *p);

void RetainBufferClose();

int TryEnterDebugSection(void);

void LeaveDebugSection(void);


int startPLC(const void *);

int stopPLC();

int __init();

void __run();

void runPLC();

void __cleanup(void);

void ResetDebugVariables(u8);

void RegisterDebugVariable(unsigned int idx);

int GetDebugData(uint32_t *tick, uint32_t *size, void **buffer);

void FreeDebugData(void);

int endDebugData();

void suspendDebug(int disable);

int GetPLCstatus(char *tx, int txlen);

void resumeDebug(void);

void __init_debug(void);

void __publish_debug(void);

int WaitDebugData(unsigned long *tick);

long AtomicCompareExchange(long *atomicvar, long compared, long exchange);

void plc_app_start(void);

void plc_app_stop(void);


u64 AtomicCompareExchange64(long long *atomicvar, long long compared, long long exchange);

void ResetLogCount(void);

uint32_t GetLogCount(u8 level);

uint32_t GetLogMessage(u8 level, uint32_t msgidx, char *buf, uint32_t max_size, uint32_t *tick, uint32_t *tv_sec,
                  uint32_t *tv_nsec);

int rte_create_task(const char *name, uint32_t, void *);

int rte_create_timer_task(const char *name, uint32_t, uint32_t, void *);

int rte_create_exti_task(const char *name, uint32_t, u8, u8, void *);

u8 fast_input(u8 a, u8 b, u8 c, u8 d, u8 e);

void fast_output(u8 a, u8 b, u8 c, u8 d, u8 e, u8 param);

#if defined(__cplusplus)
}
#endif

#endif
